﻿<Window x:Class="Eirene.WPF.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
        xmlns:local="clr-namespace:Eirene.WPF.Util"
        Title="MainWindow" Height="300" Width="550" Loaded="Window_Loaded">
    
    <Window.Resources>
        <local:ConcatenateFieldsMultiValueConverter x:Key="mvc" />
        <local:DatabindingDebugConverter x:Key="debugConverter" />
        <SolidColorBrush x:Key="ItemBrush" Color="Transparent" />
        <SolidColorBrush x:Key="SelectedItemBrush" Color="LightBlue" />
        <SolidColorBrush x:Key="HoverItemBrush" Color="Azure" />
        
        <Style x:Key="RoundedItem" TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border Name="ItemBorder" CornerRadius="10" BorderBrush="Black" BorderThickness="1" Margin="1" Background="{StaticResource ItemBrush}">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="ItemBorder" Property="Background" Value="{StaticResource SelectedItemBrush}" />
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsMouseOver" Value="True" />
                                    <Condition Property="IsSelected" Value="False" />
                                </MultiTrigger.Conditions>
                                <Setter TargetName="ItemBorder" Property="Background" Value="{StaticResource HoverItemBrush}" />
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type Button}">
            <Setter Property="Button.Background" Value="Yellow" />
            <Setter Property="IsEnabled" Value="False"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding CanSetDefaultOwner}" Value="True">
                    <Setter Property="IsEnabled" Value="True"/>
                </DataTrigger>
                <Trigger Property="IsMouseOver" Value="True" >
                    <Setter Property="Background" Value="Orange" />
                    <Setter Property="FontStyle" Value="Italic" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="DefaultOwner" TargetType="ListBoxItem">
            <Setter Property="Background" Value="LavenderBlush"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Data.IsDefault}" Value="True">
                    <Setter Property="Background" Value="Red"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <DockPanel>
        <!--Show welcome message-->
        <TextBlock Name="WelcomeMessage" 
                   Text="{Binding Path=Welcome}"
                   DockPanel.Dock="Top" FontSize="22" FontWeight="Medium" HorizontalAlignment="Center" />
        
        <!--Show list of hats-->
        <ListBox Name="Hats" ItemsSource="{Binding Path=Items}" ItemContainerStyle="{StaticResource RoundedItem}" HorizontalContentAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Label Width="80" Content="{Binding Path=Data.ItemName}" />
                        <Label Width="150" Content="{Binding Path=Data.Colour}" />
                        <Label Width="50" Content="{Binding Path=Data.Price}" ContentStringFormat="C" />
                        <Label Width="50" Content="{Binding Path=Data.Status.Name}" />
                        <ListBox Name="Owners" ItemsSource="{Binding Path=Owners}" ItemContainerStyle="{StaticResource DefaultOwner}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Name="ownerName" Text="{Binding Path=FullName}" Width="140" VerticalAlignment="Center">
                                            <TextBlock.ContextMenu>
                                                <ContextMenu>
                                                    <Menu>
                                                        <MenuItem Header="Set Default" Command="{Binding Path=SetDefaultCommand}" />
                                                    </Menu>
                                                </ContextMenu>
                                            </TextBlock.ContextMenu>
                                        </TextBlock>
                                        <!--<Button HorizontalAlignment="Right" Margin="0" Command="{Binding Path=SetDefaultCommand, Converter={StaticResource debugConverter}}" Content="Default" />-->
                                        <Button HorizontalAlignment="Right" Margin="0" Command="{Binding Path=SetDefaultCommand}" IsEnabled="{Binding CanSetDefaultOwner}" Content="Default" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </DockPanel>
</Window>
